package com.guet.controller.teacher;

import com.guet.DTO.VideoDTO;
import com.guet.DTO.VideoPageDTO;
import com.guet.VO.VideoVO;
import com.guet.result.PageResult;
import com.guet.result.Result;
import com.guet.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher/video")
@Slf4j
@CrossOrigin
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 添加视频
     *
     * @param videoDTO
     * @return
     */
    @PostMapping("add")
    public Result<Object> addVideo(@RequestBody VideoDTO videoDTO) {
        log.info("videoDTO:{}", videoDTO);
        videoService.addVideo(videoDTO);
        return Result.success();
    }

    /**
     * 分页查询视频列表
     * @param videoPageDTO
     * @return
     */
    @PostMapping
    public Result<PageResult> getPageList(@RequestBody VideoPageDTO videoPageDTO) {
        log.info("VideoPageDTO:{}", videoPageDTO);
        PageResult result = videoService.list(videoPageDTO);
        return Result.success(result);
    }

    /**
     * 根据id查询视频信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result<VideoVO> getVideoById(@PathVariable Integer id) {
        VideoVO videoVO = videoService.queryById(id);
        return Result.success(videoVO);
    }

    /**
     * 根据id删除视频
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result<Object> deleteVideoById(@PathVariable Integer id) {
        videoService.deleteById(id);
        return Result.success();
    }


}
